package bean.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import Entities.ListaDePrecio;

public class ListaPreciosDAO extends HibernateDAO{
	
	private static ListaPreciosDAO instancia;
	private static SessionFactory sf;
	
	public static ListaPreciosDAO getInstancia(){
		if(instancia == null){
			sf = (HibernateDAO.getInstancia().getSession().getSessionFactory());
			instancia = new ListaPreciosDAO();
		} 
		return instancia;
	}
	
	public void altaListaPrecios (ListaDePrecio Lp)
	{
		Session s = HibernateDAO.getInstancia().getSession();
		Transaction t = s.beginTransaction();
		s.save(Lp);
		
		t.commit();
	}


	public ListaDePrecio getListaDePrecios(Integer id) {
		Session s = HibernateDAO.getInstancia().getSession();
		Transaction t = s.beginTransaction();
		ListaDePrecio c = (ListaDePrecio) s.createQuery(" from ListaPrecios where id = :nro").setInteger("id", id).uniqueResult();
		t.commit();
		return c;
	}

	@SuppressWarnings("unchecked")
	public List<ListaDePrecio> getListasDePrecios() {
		Session s = HibernateDAO.getInstancia().getSession();
		Transaction t = s.beginTransaction();
		List<ListaDePrecio> lista = s.createQuery("from ListaPrecios").list(); 		
		t.commit();
		return lista;
	}
	
	public static void setSf(SessionFactory sf) {
		ListaPreciosDAO.sf = sf;
	}

	public static SessionFactory getSf() {
		return sf;
	}


}
